<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <base data-ice="baseUrl" href="../../">
  <title data-ice="title">Math3d/Point.js | webpack-demo1</title>
  <link type="text/css" rel="stylesheet" href="css/style.css">
  <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
  <script src="script/prettify/prettify.js"></script>
  <script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">

<header>
  <a href="./">Home</a>
  
  <a href="identifiers.html">Reference</a>
  <a href="source.html">Source</a>
  
  <div class="search-box">
  <span>
    <img src="./image/search.png">
    <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
  </span>
    <ul class="search-result"></ul>
  </div>
</header>

<nav class="navigation" data-ice="nav"><div>
  <ul>
    
  <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Circle.js~Circle.html">Circle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/CircleAndPoint.js~CircleAndPoint.html">CircleAndPoint</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Common.js~Common.html">Common</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Line.js~Line.html">Line</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndCircle.js~LineAndCircle.html">LineAndCircle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndPoint.js~PointAndLine.html">PointAndLine</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Point.js~Point.html">Point</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-EPSILON">EPSILON</a></span></span></li>
</ul>
</div>
</nav>

<div class="content" data-ice="content"><h1 data-ice="title">Math3d/Point.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import { EPSILON } from &apos;./Const.js&apos;

export default class Point {
   /**
     * &#x4E09;&#x89D2;&#x5F62;&#x7684;&#x9762;&#x79EF;,&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x4E09;&#x70B9;&#x662F;&#x5426;&#x5171;&#x7EBF;
     */
    static area(p, q, s) {
        let l1 = q.clone().sub(p)
        let l2 = s.clone().sub(q)
        let temp = l1.cross(l2)
        return temp.length() / 2
    }

      /**
     * &#x70B9;s&#x5728;pq&#x7684;&#x5DE6;&#x8FB9;&#x4E48;?
     * @param {*} p
     * @param {*} q
     * @param {*} s
     * @return &gt; 0: &#x987A;&#x65F6;&#x9488;, &lt; &#x9006;&#x65F6;&#x9488;
     * @ note https://www.cnblogs.com/wind-chaser/p/10889537.html
     *        http://www.everyinch.net/index.php/computergeometry1/
     */
    static isLeft(p, q, s) {
        let l1 = q.clone().sub(p)
        let l2 = s.clone().sub(q)
        let temp = l1.cross(l2)
        // temp &#x5728;&#x53C9;&#x79EF;&#x540E;&#x7684;&#x5411;&#x91CF;&#x7684;&#x7B2C;&#x4E09;&#x4E2A;&#x5206;&#x91CF;&#x53CD;&#x6620;&#x4E86;&#x65B9;&#x5411;
        // &#x4F8B;&#x5982;: (1,0,0) cross (0,1,0)  =&gt; (0,0,1)
        // &#x90A3;&#x4E48;(0,0,1)&#x7684;z&#x5206;&#x91CF;&#x662F;&#x6B63;&#x7684;,&#x5C31;&#x662F;&#x987A;&#x65F6;&#x9488;&#x65B9;&#x5411;,&#x5426;&#x5219;&#x5C31;&#x662F;&#x9006;&#x65F6;&#x9488;
        let ret =  temp.z
        return ret
    }

      /**
     * &#x5224;&#x65AD;&#x70B9;&#x662F;&#x5426;&#x5728;&#x591A;&#x8FB9;&#x5F62;&#x5185;
     * @param point &#x5F85;&#x5224;&#x65AD;&#x7684;&#x70B9;
     * @param points &#x7EC4;&#x6210;&#x591A;&#x8FB9;&#x5F62;&#x70B9;&#x7684;&#x6570;&#x7EC4;
     * @note &#x4E0D;&#x5305;&#x542B;&#x591A;&#x8FB9;&#x5F62;&#x8FB9;&#x4E0A;
     */
    static pointInPolygon(point, points) {
        let angle = 0
        for (let i = 0; i &lt; points.length; i++) {
            let curtent = i
            let next = (curtent + 1) % points.length
            let l1 = points[curtent].clone().sub(point)
            let l2 = points[next].clone().sub(point)
            angle += l1.angleTo(l2)
        }
        if (Math.PI * 2 - angle &lt; EPSILON) {
            return true
        } else {
            return false
        }
    }

     /**
     * &#x5224;&#x65AD;&#x4E09;&#x4E2A;&#x70B9;&#x7684;&#x4F4D;&#x7F6E;&#x5173;&#x7CFB;
     *                p2
     *
     * p0      p1
     *
     *                p2
     * @param {*} p0
     * @param {*} p1
     * @param {*} p2
     */
    static ccw(p0, p1, p2) {
        // p0,p1,p2 &#x9006;&#x65F6;&#x9488;&#x65B9;&#x5411;
        const COUNTER_CLOCKWISE = -1
        // p0,p1,p2 &#x987A;&#x65F6;&#x9488;
        const CLOCKWISE = 1
        // &#x5B8C;&#x5168;&#x76F8;&#x53CD;, p1,p2&#x5728;p0&#x7684;&#x4E24;&#x4FA7;
        const ONLINE_BACK = 3
        // &#x65B9;&#x5411;&#x76F8;&#x540C;&#xFF08;p1&#x8F83;&#x8FDC;&#xFF09;
        const ONLINE_FRONT = 4
        // &#x65B9;&#x5411;&#x76F8;&#x540C;&#xFF08;p2&#x8F83;&#x8FDC;&#xFF09;
        const ON_SEGMENT = 5

        let dir = Math3D.isLeft(p0, p1, p2)
        if (dir &gt; 0) {
            return COUNTER_CLOCKWISE
        } else if (dir &lt; 0) {
            return CLOCKWISE
        } else if (dir == 0) {
            let u = p1.clone().sub(p0)
            let v = p2.clone().sub(p0)
            let w = u.dot(v)
            if (w &lt; 0) {
                return ONLINE_BACK
            } else {
                if (u.length() &gt; v.length()) {
                    return ONLINE_FRONT
                } else {
                    return ON_SEGMENT
                }

            }
        }
    }

    /**
     *        p1
     * p2
     *        p3
     * &#x6D4B;&#x91CF;&#x89D2;&#x5EA6;
     * @param {*} p1
     * @param {*} p2
     * @param {*} p3
     */
    static angle(p1, p2, p3) {
        let line1 = p1.clone().sub(p2)
        let line2 = p3.sub(p2)
        return line1.angleTo(line2) * THREE.Math.RAD2DEG
    }

    /**
     * &#x9A8C;&#x8BC1;&#x4E09;&#x89D2;&#x5F62;&#x7684;&#x5408;&#x6CD5;
     */
    static isTriangle(a, b, c) {
        if (a + b &gt; c &amp;&amp; a + c &gt; b &amp;&amp; b + c &gt; a) {
            return true
        } else {
            return false
        }
    }
}
</code></pre>

</div>

<footer class="footer">
  Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>

<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>
